#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@File: xiaoNengPlatView.py
@Author: lijk34925 
@Date: 2024/8/16 15:56
@desc: 请补充本模块功能说明
"""
import threading

from fastapi import APIRouter, Form

from BladeFerm.utils.basic_opration import is_dir_exist
from function.Plat.FlowReport import FlowReportObject
from BladeFerm.Lib.Common import logger

FlowReport = FlowReportObject()
router = APIRouter()

plat_path = '../static/platform/'
is_dir_exist(plat_path)


# 报表汇总相关接口
@router.get("/queryTables/")
def query_tables():
    result = FlowReport.query_origin_tables()
    return {'result': result, 'status': 200, 'message': f'获取报表名称列表OK！'}


@router.get("/queryDownloadProgress/")
def query_tables_progress():
    result = FlowReport.query_download_progress()
    return {'result': result, 'status': 200, 'message': f'获取报表进度成功！'}


@router.post("/downloadTables/")
async def download_tables(username: str = Form('lijk34295'), password: str = Form(''), tables: str = Form()):
    logger.info(f'username: {username}, password: {password}')
    params = {'username': username, 'password': password, 'tables': tables.split(',')}
    t = threading.Thread(target=FlowReport.download_tables, args=(params,))
    t.start()
    return {'result': True, 'status': 200, 'message': '下载成功！'}